#include <iostream>
#include <cmath>
#include <unordered_map>
#include <string>

bool prime(int x) {
    if (x == 1) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(x)) + 1; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::unordered_map<std::string, std::string> a = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };

    std::string input;
    std::getline(std::cin, input);
    std::string f = "";
    bool flag = true;
    std::string s[100];
    int n = 0;
    std::string word;
    for (int i = 0; i < input.length(); i++) {
        if (input[i] == ' ') {
            s[n++] = word;
            word = "";
        } else {
            word += input[i];
        }
    }
    s[n++] = word;

    if (n < 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        if (a.find(s[i]) == a.end()) {
            std::cout << "Wrong input" << std::endl;
            return 0;
        }
    }

    for (int i = 0; i < n; i++) {
        f += a[s[i]];
    }

    int num = std::stoi(f);
    if (num < 100 || num > 999) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int d = 0, g = 0;
    for (int i = num - 1; i >= 100; i--) {
        if (prime(i)) {
            d = i;
            break;
        }
    }
    for (int i = num + 1; i < 1000; i++) {
        if (prime(i)) {
            g = i;
            break;
        }
    }

    if (num - d < g - num) {
        std::cout << d << std::endl;
    } else {
        std::cout << g << std::endl;
    }

    return 0;
}
